/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/




#if !defined(AFX_PGLGRAPHBITDLG_H__4D439DF6_83C2_11D4_8268_00A024D26A1F__INCLUDED_)
#define AFX_PGLGRAPHBITDLG_H__4D439DF6_83C2_11D4_8268_00A024D26A1F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// GraphGLBitDlg.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CPGLDialog dialog

#include <pgl/mfc/PGLMouse.h>
#include <pgl/igfx/GDIpInterface.h>
#include <pgl/igfx/GDIpHelper.h>
#include <pgl/newmenu/DialogEx.h>
#include <pgl/core/PGLArchive.h>
#include <pgl/mfc/PGLEvent.h>

#include <boost/smart_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <pgl/core/static_ptr.hpp>
#include <pgl/core/PGL.h> //PGL_DECLARE_SMART_PTR




class CPGLDialogList;

/*! 
	\defgroup PGLMFCGroup Plot Graphic Library MFC Interface (PGLMFC)
*/

/*! \brief A PGL graph dialog class.

To use this class, you must:
	- create a CPGLRegion object (on the heap)
	- create a dialog
	- attach the CPGLRegion object to the dialog by means of the constructor or the SetRegion function.
	- launch modal or modeless

The default behavior of the dialog is to apply ZoomAll to the region. However, you can disable this feature by
setting the corresponding flag (CPGLDialog::OptionNoZoomAll) in the constructor.

Note that the region pointer is deleted on dialog destruction.
\ingroup PGLMFCGroup
*/
class PGLMFC_EXT_CLASS CPGLDialog : public CDialogEx
{
public:
	//! \name Constructors
	//@{
	//! Option flag enumeration
	enum EOption
	{
		//! No zoom all in OnInitDialog
		OptionNoZoomAll =			0x0001,
		//! Triple buffering (best for animated charts)
		OptionTripleBuffering =		0x0002,
		//! metafile clipboard (default is bitmap)
		OptionClipboardMetafile =	0x0004,
		//! no taskbar
		OptionNoTaskBar=			0x0008,
		//! no toolbar
		OptionNoToolBar=			0x0010
	};

	/*! \brief Default constructor

	\param pParent, pointer to parent window. (default is NULL)
	\param pRegion, pointer to the CPGLRegion object. (default is NULL)
	\param dwFlags, option flag (DEFAULT is 0)

	
	*/
	CPGLDialog(
        CWnd* pParent = NULL, 
        CPGLRegionPtr pRegion = CPGLRegionPtr(), 
        DWORD dwFlags = 0
        );   
	//! Standard desctructor
	~CPGLDialog();
	//@}

	//! \name Interface and GDI+ helper
	//@{
	//! return reference to gfx interface
	gfxinterface::CGDIpInterface& GetGfxInterface()				{	return m_GDIpInterface;};
	//! return reference to gfx interface, const
	const gfxinterface::CGDIpInterface& GetGfxInterface() const	{	return m_GDIpInterface;};
	//! returns reference to GDI+ helper
	pgl::CGDIpHelperRegion& GetGDIpHelper()						{	return m_GDIpHelper;};
	//! returns reference to GDI+ helper, const
	const pgl::CGDIpHelperRegion& GetGDIpHelper() const			{	return m_GDIpHelper;};
	//@}

	//! \name Region
	//@{
	//! return graph pointer
	CPGLRegionPtr GetRegion()				{	return m_pRegion;};
	/*! Sets the region

	\param pRegion a pointer to a region (must be allocated on the heap)
	*/
	void SetRegion(CPGLRegionPtr pRegion);
	//! Destroy region
	void CleanRegion();
	//@}

	//! \name Resizing state
	//@{
	//! The view has been resized, and the charts have to be refreshed
	void PostResize()					{	m_bPostResize = true;};
	//! return true if refreshing is needed (used internally)
	bool IsResizeNeeded()				{	return m_bPostResize;};
	//! reset resize bit
	void ResetResizeState()				{	m_bPostResize = false;};
	//@}

	//! \name Redrawing
	//@{
	//! enables disables triple buffering
	void SetTripleBuffering(bool on = true);
	//! Makes rebuilding memory bitmap and redrawing the chart
	void SetDirty();
	//! Makes rebuilding memory bitmap and redrawing the chart
	void SetFrontDirty();
	//! Makes blitting of memory bitmap
	void SetCacheDirty();
	//@}

	//! \name Event
	//@{
	void SetEvent( CPGLEventPtr pEvent);
	CPGLEventPtr GetEvent()								{	return m_pEvent;};
	const CPGLEventPtr GetEvent()	const				{	return m_pEvent;};
	void ClearEvent();
	//@}

	//! \name Exporting
	//@{
	//! Accessing CPGLArchive object
	CPGLArchive& GetArchive()							{	return m_archive;};
	//! Accessing CPGLArchive object, const
	const CPGLArchive& GetArchive()	const 				{	return m_archive;};
	//@}

	//! \name Modeless dialog function
	//@{
	//! Sets pointer to dialog manager
	void SetDialogManager(CPGLDialogList* pDialogManager)	{	m_pDialogManager = pDialogManager;}; 
	//@}

	//! \name Clipboard
	//@{
	//! Sets clipboard type
	void SetClipboardType(CPGLArchive::EClipBoardType eClipboardType)	{	m_eClipboardType = eClipboardType;};
	//! returns clipboard type
	CPGLArchive::EClipBoardType GetClipboardType() const				{	return m_eClipboardType;};
	//@}

	//! \name Identification
	//@{
	//! Testing ID of dialog
	bool IsID( DWORD dwID) const	{	return (DWORD)m_hWnd == dwID; 	};
	//! returns the ID
	DWORD GetID() const				{	return (DWORD)m_hWnd;};
	//@}

// Dialog Data
	//{{AFX_DATA(CPGLDialog)
	enum { IDD = IDD_PGL_DIALOG_GRAPH };
	// NOTE: the ClassWizard will add data members here
	//}}AFX_DATA


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CPGLDialog)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:

	// Generated message map functions
	//{{AFX_MSG(CPGLDialog)
	virtual BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnFileExport();
	afx_msg void OnEditCut();
	afx_msg void OnEditCopy();
	afx_msg void OnEditPaste();
	afx_msg void OnEditDelete();
	afx_msg void OnSelectionOrderMovedown();
	afx_msg void OnSelectionOrderMoveup();
	afx_msg void OnSelectionOrderToback();
	afx_msg void OnSelectionOrderTofront();
	afx_msg void OnSelectionSelectall();
	afx_msg void OnSelectionUnhideall();
	afx_msg void OnSelectionUnselect();
	afx_msg void OnViewSelect();
	afx_msg void OnViewPan();
	afx_msg void OnViewProperties();
	afx_msg void OnViewZoom();
	afx_msg void OnViewZoombox();
	afx_msg void OnViewZoomAll();
	afx_msg void OnClose();
	afx_msg void OnDestroy();
	afx_msg void OnFileSave();
	afx_msg void OnFileOpen();
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnUpdatePglViewZoombox(CCmdUI* pCmdUI);
	afx_msg void OnUpdatePglViewZoom(CCmdUI* pCmdUI);
	afx_msg void OnUpdatePglViewPan(CCmdUI* pCmdUI);
	afx_msg void OnFilePrint();
	afx_msg void OnEditCopytoclipboard();
	afx_msg void OnViewRefreshaxis();
	afx_msg void OnClipboardtypeBitmap();
	afx_msg void OnClipboardtypeMetafile();
	afx_msg void OnUpdateClipboardtypeBitmap(CCmdUI *pCmdUI);
	afx_msg void OnUpdateClipboardtypeMetafile(CCmdUI *pCmdUI);
	afx_msg void OnViewAntialiasingText();
	afx_msg void OnUpdateViewAntialiasingText(CCmdUI* pCmdUI);
	afx_msg void OnViewAntialiasingGraphics();
	afx_msg void OnUpdateViewAntialiasingGraphics(CCmdUI* pCmdUI);
	afx_msg void OnViewAntialiasingCubictextureinterpolation();
	afx_msg void OnUpdateViewAntialiasingCubictextureinterpolation(CCmdUI* pCmdUI);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnRButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnFigureImportcsvfile();
	afx_msg void OnEditClearchart();
	afx_msg void OnAboutAbout();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
protected:
	void UpdateStatusBar();

	CPGLMouse m_mouse;
	CPGLRegionPtr m_pRegion;
	DWORD m_uPointedRegion;
	CPGLEventPtr m_pEvent;
	HICON m_hIcon;
	CPGLDialogList* m_pDialogManager;
	DWORD m_dwFlags;
	CPGLArchive::EClipBoardType m_eClipboardType;
	CPGLArchive m_archive;

	gfxinterface::CGDIpInterface m_GDIpInterface;
	pgl::CGDIpHelperRegion m_GDIpHelper;

	bool m_bPostResize;
public:
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
};


//
// PGL_DECLARE_SMART_PTR( CPGLDialog ); //  [4/2/2009 JYB]

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_PGLGRAPHBITDLG_H__4D439DF6_83C2_11D4_8268_00A024D26A1F__INCLUDED_)
